Skip to content

Use header constants across the handler package - #301

Merged
andrew merged 1 commit into
mainfrom
lint-header-constants
Sep 2, 2026
Merged

Use header constants across the handler package#301
andrew merged 1 commit into
mainfrom
lint-header-constants

Conversation

@andrew

@andrew andrew commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

goconst tripped on main after #259 landed on top of #280: five composite-literal occurrences each of "Content-Length" and "Content-Type" across container.go, container_manifest.go, container_tags.go, handler.go, and swift.go crossed the min-occurrences: 5 threshold. Neither PR hit it alone; the CI lint job on #259's rebased head failed but auto-merge proceeded because lint is not a required check.

Add headerContentType and headerContentLength beside the existing headerAcceptEncoding and use them throughout the package rather than only at the flagged sites, so the next handler that adds one does not re-trip the check.

goconst tripped on main after #259 landed on top of #280: five
composite-literal occurrences each of "Content-Length" and
"Content-Type" across container.go, container_manifest.go,
container_tags.go, handler.go, and swift.go crossed the
min-occurrences: 5 threshold. Neither PR hit it alone.

Add headerContentType and headerContentLength beside
headerAcceptEncoding and use them throughout the package rather than
only at the flagged sites, so the next handler that adds one does not
re-trip the check.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The changes are a mechanical, package-local refactor to shared header-name constants with no functional behavior changes observed.

Pull request overview

This PR standardizes HTTP header key usage across the internal/handler package by introducing shared constants for Content-Type and Content-Length, preventing goconst from flagging repeated header strings and reducing future duplication.

Changes:

  • Added headerContentType and headerContentLength constants alongside the existing headerAcceptEncoding.
  • Replaced Content-Type / Content-Length string literals with the new constants across handler implementations.
  • Updated header-copying/header-proxying loops to use the constants for consistent header key handling.
File summaries
File Description
internal/handler/handler.go Defines headerContentType / headerContentLength and uses them in shared handler utilities.
internal/handler/container.go Switches container blob response header setting/copying to constants.
internal/handler/container_manifest.go Uses constants when reading/writing/copying manifest Content-* headers.
internal/handler/container_tags.go Uses constants for cached tag list Content-* metadata and header copying.
internal/handler/swift.go Uses constants for Swift archive/metadata/problem responses and header copying.
internal/handler/rpm.go Uses headerContentType for RPM download responses.
internal/handler/pypi.go Uses headerContentType when serving rewritten HTML/JSON responses.
internal/handler/pub.go Uses headerContentType when serving proxied/rewritten JSON metadata.
internal/handler/nuget.go Uses headerContentType when serving proxied/rewritten JSON responses.
internal/handler/npm.go Uses headerContentType when serving proxied/rewritten package metadata.
internal/handler/hex.go Uses headerContentType for passthrough and rewritten hex package responses.
internal/handler/helm.go Uses headerContentType when defaulting chart content type.
internal/handler/gradle.go Uses constants for Gradle build-cache Content-Type and Content-Length responses.
internal/handler/gem.go Uses headerContentLength in case-insensitive header filtering logic.
internal/handler/debian.go Uses headerContentType for Debian package download responses.
internal/handler/conda.go Uses headerContentType for proxied/rewritten JSON responses.
internal/handler/composer.go Uses headerContentType for Composer JSON responses.
internal/handler/cargo.go Uses headerContentType for Cargo config/index responses.
Review details
  • Files reviewed: 18/18 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@andrew
andrew merged commit c5e1483 into main Sep 2, 2026
9 checks passed
@andrew
andrew deleted the lint-header-constants branch September 2, 2026 12:22
andrew added a commit that referenced this pull request Sep 2, 2026
Compute real manifest digests in #280's fixture upstreams so the new
verification accepts them, and add headerETag / headerLastModified to
#301's constant set so goconst passes with the new occurrences.
andrew added a commit that referenced this pull request Sep 3, 2026
Compute real manifest digests in #280's fixture upstreams so the new
verification accepts them, and add headerETag / headerLastModified to
andrew added a commit that referenced this pull request Sep 3, 2026
* Add Homebrew JSON API and bottle proxy support

* Fix Homebrew HEAD offline fallback and non-sha256 OCI manifest handling

Route Homebrew API HEAD requests through ProxyCached so a warm cache
answers without an upstream call and stale entries are served when the
upstream is unreachable. HEAD still reaches upstream as HEAD when
metadata caching is disabled.

Limit OCI manifest digest verification to sha256 references and
Docker-Content-Digest headers so other digest algorithms are proxied
instead of rejected, and log the failing expected value.

* Reconcile with #280 and #301 after rebase

Compute real manifest digests in #280's fixture upstreams so the new
verification accepts them, and add headerETag / headerLastModified to

* Send fixed Accept for Homebrew API and match If-None-Match properly

The Homebrew API cache key does not include Accept, so replaying the
client header could serve one representation under another; the API
does not negotiate anyway. Compare If-None-Match with weak comparison,
list splitting and "*" per RFC 7232 instead of string equality, and
apply the same helper to the metadata and swift responders.

* Reconcile with #298 and #304 after rebase

Move the configureScanning doc comment back to its function after the
auto-merge stacked it on mountProtocolHandlers, and drop the second
ETag/Last-Modified set in writeMetadataCachedResponse now that the
pre-304 set covers both response paths.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants